document.querySelector('#btn-login').addEventListener('click', async function () {
  const form = document.querySelector('.login-form')
  const data = serialize(form, { empty: true, hash: true })
  const { username, password } = data
  if (username === '' || password === '') {
    showToast('用户名或密码不能为空')
    return
  }
  try {
    const res = await axios.post('/login', data)
    if (res.code !== 10000) return showToast(res.message)
    showToast(res.message)
    localStorage.setItem('token', res.data.token)
    localStorage.setItem('username', res.data.username)
    setTimeout(() => {
      location.href = './index.html'
    }, 1500)
  } catch (err) {
    showToast(err.response.data.message)
  }
})
